package allrobots.controller;

import allrobots.DispensingMachineThread.DMFinishToSystem;
import allrobots.DispensingMachineThread.DispensingMachineThread;
import allrobots.test.testThread;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/webapi")
@CrossOrigin // 允许所有域的跨域请求
public class WebController {

    @PostMapping("/getorder")
    @ResponseBody
    //收到前端信息后，将两个队列进行比较，启动机器人
    //orders负责保存订单
    //toRobotOrders负责交付订单，看交付和保存大小是否一样
    public Map<String, Object> getorder(@RequestBody Map<String, Object> orders_num) {
        String order=(String) orders_num.get("order_num");
        System.out.println("新发来的订单号："+order);
//        System.out.println(orders_num.size());
        DispensingMachineThread.orders.add(order);
        //调用线程去获取机器人信息
        new Thread(new DMFinishToSystem()).start();
        // 返回一个Map，Spring会自动转换为JSON
        Map<String, Object> response = new HashMap<>();
        response.put("status", "success");
        response.put("message", "我收到了你的请求");

        return response;
    }
}
